package com.bw.spark02.rdd.broadcast

import org.apache.log4j.{Level, Logger}
import org.apache.spark.{SparkConf, SparkContext}

object BroadcastTest1 {
    
    def main(args: Array[String]): Unit = {
        Logger.getLogger("org").setLevel(Level.ERROR)

        val sparkConf = new SparkConf().setAppName(this.getClass.getSimpleName).setMaster("local")
        val sc = new SparkContext(sparkConf)

        // 在Driver定义一个变量
        val factor = 100

        //在worker执行
        val rdd = sc.parallelize(Array(1,2,3,4))
        //广播出去
        val f = sc.broadcast(factor)
        rdd.map(x => {
            val factor = f.value
            val y = x * factor
            y * y
        }
        )
    }
}
